package com.zbkj.admin.controller;

import com.zbkj.admin.service.AdminPartnerHandler;
import com.zbkj.common.exception.ExceptionCodeEnum;
import com.zbkj.common.model.user.Partner;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.user.AdminPartnerSaveRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.validation.CreateValidatorGroup;
import com.zbkj.common.validation.UpdateValidatorGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther:
 * @Date: 2024/9/11 21:42
 * @Description:
 */
@RestController
@RequestMapping("api/admin/partner")
@Api(tags = "服务端-合作伙伴管理服务")
public class AdminPartnerController {

    @Autowired
    private AdminPartnerHandler adminPartnerHandler;

    @ApiOperation(value="获取邀请码")
    @GetMapping("/getInviteCode")
    public CommonResult getInviteCode() {
        return CommonResult.success(adminPartnerHandler.getInviteCode(), ExceptionCodeEnum.SUCCESS.getMessage());
    }

    @ApiOperation(value = "合作伙伴列表")
    @PostMapping(value = "/list")
    public CommonResult<CommonPage<Partner>> list(@RequestBody @Validated PageParamRequest queryRequest) {
        return CommonResult.success(CommonPage.restPage(adminPartnerHandler.list(queryRequest)));
    }

    @ApiOperation(value = "新增合作伙")
    @PostMapping(value = "/save")
    public CommonResult save(@RequestBody @Validated({CreateValidatorGroup.class}) AdminPartnerSaveRequest partnerRequest) {
        adminPartnerHandler.saveOrUpdate(partnerRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "编辑合作伙")
    @PostMapping(value = "/update")
    public CommonResult update(@RequestBody @Validated({UpdateValidatorGroup.class}) AdminPartnerSaveRequest partnerRequest) {
        adminPartnerHandler.saveOrUpdate(partnerRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "获取合作伙伴信息")
    @GetMapping(value = "/getInfo/{id}")
    public CommonResult<Partner> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(adminPartnerHandler.getInfo(id));
    }

    @ApiOperation(value = "删除合作伙")
    @GetMapping(value = "/delInfo/{id}")
    public CommonResult delInfo(@PathVariable("id") Long id) {
        adminPartnerHandler.delPartner(id);
        return CommonResult.success();
    }

}
